package com.basin.common.mp.base;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * @author: Sam ZHONG | sammy1997@aliyun.com
 */
@Data
public class BaseEntity implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    @TableId
    private Long id;
    @TableField(fill = FieldFill.INSERT)
    private Timestamp createTime;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Timestamp updateTime;
    @TableField(fill = FieldFill.INSERT)
    private String createUser;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String updateUser;
    @TableLogic(delval = "0", value = "1")
    @TableField(fill = FieldFill.INSERT)
    private Integer status;
    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) // 入参能接 但返回时不序列化
//    @JsonProperty(access = JsonProperty.Access.READ_ONLY) // 反之
    private Integer current;
    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) // 入参能接 但返回时不序列化
//    @JsonProperty(access = JsonProperty.Access.READ_ONLY) // 反之
    private Integer size;

    public Integer getCurrent() {
        if (current == null || current <= 0) return 1;
        return current;
    }

    public Integer getSize() {
        if (size == null || size <= 0) return 10;
        return Math.min(size, 2000);
    }
}
